package com.lanou3g.code0512.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RequestServlet",urlPatterns = "/s")
public class RequestServlet extends HttpServlet {


    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        //在获取参数之前  告诉Tomcat 参数是utf8编码的
        //在get请求中 这种方式不行
//        request.setCharacterEncoding("utf8");
        String keyWord=request.getParameter("keyWord");
//        byte[]bytes=keyWord.getBytes("iso-8859-1");
//        keyWord = new String(bytes,"utf-8");
        response.getWriter().println("用户输入的是:"+keyWord);

    }
}
